package etp.client.gui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ETPMenu extends AbsolutePanel{

	private VerticalPanel pnlMenu = new VerticalPanel();
	
	public ETPMenu(){
		
		this.setStylePrimaryName("etp-ETPMenu");
		
		this.add(pnlMenu);
		
		this.pnlMenu.getElement().setAttribute("style", 
				"margin-left: auto;" +
				"margin-right: auto;" +
				"padding-top: 20px;");
	}
	
	public void addMenuItem(Widget w){
		ETPMenuItem item = new ETPMenuItem();
		
		item.add(w);
		
		this.pnlMenu.add(item);
	}
	
	public void addMenuItem(String text, ClickHandler handler){
		Label lbl = new Label(text);
		ETPMenuItem item = new ETPMenuItem();
		
		item.add(lbl);
		
		item.addClickHandler(handler);
		
		this.pnlMenu.add(item);
	
	}
	
	protected class ETPMenuItem extends AbsolutePanel implements HasClickHandlers{
		
		public ETPMenuItem(){
			this.setStylePrimaryName("etp-ETPMenuItem");	
		}

		@Override
		public HandlerRegistration addClickHandler(ClickHandler handler) {
			return this.addDomHandler(handler, ClickEvent.getType());
		}
	}
}
